<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__ADMIN__css/font.css">
    <link rel="stylesheet" href="__ADMIN__css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__js/jq.js"></script>
    <script type="text/javascript" src="__ADMIN__lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="__ADMIN__html5.min.js"></script>
    <script src="__ADMIN__respond.min.js"></script>
    <![endif]-->
    <style>
        th td {
            text-align: center;
        }
    </style>
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
       系统设置 》 网站设置
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:window.location.reload();" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加字段','{:url("admin/config_field/addField")}')">添加</button>
        <span class="x-right" style="line-height:40px">共有数据：{$count|default=0} 条</span>
    </xblock>
    <div style="width: 800px">
        <form   class="layui-form"  action="" >
                <?php  foreach($confList as $key=>$value):  ?>
                <!--输入框-->
                    <?php if($value['field_type'] == 1):  ?>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><?php  echo $value['cn_name'] ?></label>
                            <div class="layui-input-block">
                                <input type="text" name="<?php  echo $value['en_name'] ?>"  id="<?php  echo $value['en_name'] ?>"  value="<?php  echo $value['value'] ?>" autocomplete="off" class="layui-input">
                            </div>
                        </div>
            <!--单选框-->
                    <?php elseif($value['field_type'] == 2):
                        $radioArr = explode(',',$value['values']);
                    ?>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><?php  echo $value['cn_name'] ?></label>
                        <div class="layui-input-block">
                                <?php  foreach($radioArr as $k=>$v):  ?>
                                    <input    <?php if($value['value'] == $v):  ?>  checked  <?php endif;?>  type="radio" name="<?php  echo $value['en_name'] ?>" value="<?php  echo $v; ?>" title="<?php  echo $v; ?>">
                                <?php  endforeach;?>
                        </div>
                    </div>
            <!--复选框-->
                     <?php elseif($value['field_type'] == 3):
                      $checkArr = explode(',',$value['values']);
                      ?>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><?php  echo $value['cn_name'] ?></label>
                        <div class="layui-input-block">
                            <?php  foreach($checkArr as $k=>$v):  ?>
                            <input
                            <?php if($value['value']):
                            $checkedArr = explode(',',$value['value']);?>
                              <?php  foreach($checkedArr as $a=>$b):  ?>
                                    <?php if($b == $v):?>
                                        <?php echo 'checked';?>
                                     <?php endif;?>
                                <?php  endforeach;?>
                            <?php endif;?>
                                    type="checkbox" name="<?php  echo $value['en_name'] ?>[]"  value="<?php  echo $v; ?>"  title="<?php echo $v; ?>">
                            <?php  endforeach;?>
                        </div>
                    </div>
                <!--下拉框-->
                    <?php elseif($value['field_type'] == 4):
                        $selectedArr = explode(',',$value['values']);
                     ?>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><?php  echo $value['cn_name'] ?></label>
                            <div class="layui-input-block">
                                <select name="<?php  echo $value['en_name'] ?>">
                                    <?php  foreach($selectedArr as $k=>$v): ?>
                                        <option   <?php if($value['value'] == $v):  ?>  selected  <?php endif;?>          value="<?php echo $v; ?>"><?php echo $v; ?></option>
                                    <?php  endforeach;?>
                                </select>
                            </div>
                        </div>
                    <?php elseif($value['field_type'] == 5):  ?>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label"><?php  echo $value['cn_name'] ?></label>
                            <div class="layui-input-block">
                                <textarea name="<?php  echo $value['en_name'] ?>" placeholder="请输入内容" class="layui-textarea"><?php  echo $value['value'] ?></textarea>
                            </div>
                        </div>
                    <?php elseif($value['field_type'] == 6):  ?>
                        <div class="layui-form-item">
                            <label for="stock_num" class="layui-form-label">
                                <?php  echo $value['cn_name'] ?>
                            </label>
                            <div class="layui-input-block">
                                <div  style="display: flex">
                                <input style="width: 600px"  class="layui-input" type="text"  id="<?php echo $value['en_name'] ?>"  name="<?php  echo $value['en_name'] ?>"  value="<?php  echo $value['value'] ?>" >
                                    <p style="margin-left: 20px" data-id ='<?php echo $value['en_name']; ?>'  class="layui-btn demoMore"  >上传</p>
                                    <div>
                                        <?php if($value['value']):?>
                                            <a id="href_<?php echo $value['en_name']; ?>" target="_blank"  href="/<?php  echo $value['value'] ?>"><img id="src_<?php echo $value['en_name']; ?>"  style="height: 38px;border: 1px solid red;margin-left: 15px" src="/<?php  echo $value['value'] ?>"/> </a>
                                        <?php else: ?>
                                            <a  id="href_<?php echo $value['en_name']; ?>" target="_blank" href="/static/admin/images/yulan.png"><img id="src_<?php echo $value['en_name']; ?>"  style="height: 38px;border: 1px solid red;margin-left: 15px" src="/static/admin/images/yulan.png"/> </a>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php elseif($value['field_type'] == 7):  ?>
                    <div class="layui-form-item">
                        <label for="stock_num" class="layui-form-label">
                            <?php  echo $value['cn_name'] ?>
                        </label>
                        <div class="layui-input-block">
                            <div  style="display: flex">
                                <input style="width: 600px"  class="layui-input" type="text"  id="<?php echo $value['en_name'] ?>"  name="<?php  echo $value['en_name'] ?>"  value="<?php  echo $value['value'] ?>" >
                                <p style="margin-left: 20px" data-id ='<?php echo $value['en_name']; ?>'  class="layui-btn  fileUp"  >上传</p>
                            </div>
                        </div>
                    </div>
                        <?php elseif($value['field_type'] == 8):  ?>
                        <div class="layui-form-item">
                            <label for="stock_num" class="layui-form-label">
                                <?php  echo $value['cn_name'] ?>
                            </label>
                            <div class="layui-input-block">
                                <input type="text" style="width: 200px" name="<?php  echo $value['en_name'] ?>"  id="<?php  echo $value['en_name'] ?>"  value="<?php  echo $value['value'] ?>" autocomplete="off" class="layui-input datetime">
                            </div>
                        </div>
                    <?php endif;?>
            <?php  endforeach;?>
            <div  class="layui-form-item">
                <button style="margin-left: 200px" type="button"  class="layui-btn" lay-filter="add" lay-submit="">
                   保存
                </button>
            </div>

        </form>
    </div>
</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        $('.datetime').each(function() {
            laydate.render({
                elem: this       //使用this指向当前元素,不能使用class名, 否则只有第一个有效
                ,type: 'datetime'
            });
        })
    });
    layui.use('upload', function() {
        var $ = layui.jquery
            , upload = layui.upload;
        //同时绑定多个元素，并将属性设定在元素上
        upload.render({
            elem: '.demoMore'
            , url:"{:url('admin/conf/uploadImage')}"
            ,accept:'image'
            ,field:'image'
            , done: function (res, index, upload) {
                var item = this.item;
                if (res.code == 0){
                    layer.msg('上传成功！', {icon: 6},function() {
                        var inputId = item.attr('data-id');
                        $('#'+inputId).val(res.img);
                        $('#href_'+inputId).attr('href', '/'+res.img);
                        $('#src_'+inputId).attr('src', '/'+res.img);
                    });
                }else{
                    layer.msg(res.message);
                }
            }
        });
    });

    layui.use('upload', function() {
        var $ = layui.jquery
            , upload = layui.upload;
        //同时绑定多个元素，并将属性设定在元素上
        upload.render({
            elem: '.fileUp'
            , url:"{:url('admin/conf/uploadDocument')}"
            ,accept:'file'
            ,field:'file'
            , done: function (res, index, upload) {
                var item = this.item;
                if (res.code == 0){
                    layer.msg('上传成功！', {icon: 6},function() {
                        var inputId = item.attr('data-id');
                        $('#'+inputId).val(res.img);
                    });
                }else{
                    layer.msg(res.message);
                }
            }
        });
    });

    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;
        //监听提交
        form.on('submit(add)', function(data){
            //alert(data.field);
            $.ajax({
                type:'post',
                data:data.field,
                dataType:'json',
                url:"{:url('admin/conf/inputData')}",
                success:function (data) {
                    if (data.code == 0){
                        layer.alert(data.message, {icon: 6});
                    }else{
                        layer.alert(data.message, {icon: 5});
                        return false;
                    }
                }
            })
        });
    });
</script>
</body>

</html>